﻿Imports DTO
Imports System.Data
Imports System.Data.SqlClient

Public Class NhanVienDAO
    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim sql = "Select * From NhanVien"
        Dim cn As SqlConnection = DataProviders.ConnectDB()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub Them(ByVal nv As NhanVienDTO)
        Dim cn As SqlConnection = DataProviders.ConnectDB()
        Dim sql = String.Format("Insert into NhanVien values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', {7}, {8})", nv.MaNV, nv.TenNV, nv.MaTK, nv.DiaChi, nv.Email, nv.DienThoai, nv.NgayVaoLam, nv.LuongCB, nv.HeSoLuong)
        Dim cmd As SqlCommand = New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub Xoa(ByVal maNV As String)
        Dim cn As SqlConnection = DataProviders.ConnectDB()
        Dim sql = String.Format("Delete From NhanVien where MaNV = '{0}'", maNV)
        Dim cmd As SqlCommand = New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub CapNhat(ByVal nv As NhanVienDTO)
        Dim cn As SqlConnection = DataProviders.ConnectDB()
        Dim sql = String.Format("Update NhanVien Set TenNV = '{0}',MaTK = '{1}',DiaChi = '{2}',Email = '{3}',DienThoai = '{4}',NgayVaoLam = '{5}',LuongCB = {6},hsLuong = {7} where MaNV = '{8}'", nv.TenNV, nv.MaTK, nv.DiaChi, nv.Email, nv.DienThoai, nv.NgayVaoLam, nv.LuongCB, nv.HeSoLuong, nv.MaNV)
        Dim cmd As SqlCommand = New SqlCommand(sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Function TimTheoTen(ByVal Ten As String) As DataTable
        Dim dt As New DataTable()
        Dim sql = String.Format("select * from NhanVien Where TenNV = '{0}'", Ten)
        Dim cn As SqlConnection = DataProviders.ConnectDB()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Function TimTheoMa(ByVal Ma As String) As DataTable
        Dim dt As New DataTable()
        Dim sql = String.Format("select * from NhanVien Where MaNV = '{0}'", Ma)
        Dim cn As SqlConnection = DataProviders.ConnectDB()
        Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
End Class
